package Acwing.基础算法;

import java.util.Scanner;

/**
 * @Title: prefixSum2
 * @Author 贾金博
 * @Package Acwing.基础算法
 * @Date 2025/4/9 下午5:51
 * @description: 二维的前缀和
 */
public class prefixSum2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        int[][] a = new int[n + 10][m + 10];
        int[][] sum = new int[n + 10][m + 10];
        sum[0][0] = 0;
        a[0][0] = 0;

        for(int i = 1; i <= n; i ++ ) {
            for(int j = 1; j <= m; j ++ ) {
                a[i][j] = sc.nextInt();
                sum[i][j] = sum[i - 1][j] + sum[i][j - 1] -sum[i - 1][j - 1] + a[i][j];
            }
        }

        while(q -- > 0 ) {
            int x1, y1, x2, y2;
            x1 = sc.nextInt();
            y1 = sc.nextInt();
            x2 = sc.nextInt();
            y2 = sc.nextInt();

            //
            System.out.println(sum[x2][y2] - sum[x1 - 1][y2] -sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1]);

        }
    }
}
